package STUDENT.TRINHQUANGXUANDUC.OPPS.QuanLyNhanSu.Views;

import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import STUDENT.TRINHQUANGXUANDUC.OPPS.QuanLyNhanSu.Controllers.Controllers;
import STUDENT.TRINHQUANGXUANDUC.OPPS.QuanLyNhanSu.Entry.Phongban;

public class ViewPhongban extends JFrame {

	private JPanel contentPane;
	private JTextField txtid;
	private JTextField txtten;
	private JTextField txtheso;
	private JTextField txtmota;
	private JTextArea taphongban;
	private JScrollPane scrollphongban;
	Controllers control = new Controllers();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ViewPhongban frame = new ViewPhongban();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ViewPhongban() {
		control.loaddata();
		setTitle("Quan li phong ban");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 567, 415);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JLabel lblMaPhongBan = new JLabel("Ma phong ban");

		JLabel lblTenPhongBan = new JLabel("Ten phong ban");

		JLabel lblHeSoCong = new JLabel("He so cong viec");

		JLabel lblMoTa = new JLabel("Mo ta");

		txtid = new JTextField();
		txtid.setColumns(10);

		txtten = new JTextField();
		txtten.setColumns(10);

		txtheso = new JTextField();
		txtheso.setColumns(10);

		txtmota = new JTextField();
		txtmota.setColumns(10);

		JButton btnThem = new JButton("Them");
		btnThem.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Phongban pb = new Phongban();
				pb.setIdphongban(Integer.parseInt(txtid.getText()));
				pb.setTenphong(txtten.getText());
				pb.setHesocongviec(Integer.parseInt(txtheso.getText()));
				pb.setMota(txtmota.getText());
				control.addPhongban(pb);
				taphongban.setText(loadDataPhongBan());
			}
		});
		taphongban = new JTextArea();
		taphongban.setRows(3);
		taphongban.setColumns(5);
		taphongban.setText(loadDataPhongBan());

		scrollphongban = new JScrollPane(taphongban);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(scrollphongban, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 414,
										Short.MAX_VALUE)
								.addGroup(gl_contentPane.createSequentialGroup()
										.addGroup(
												gl_contentPane.createParallelGroup(Alignment.LEADING)
														.addComponent(lblMaPhongBan)
														.addComponent(lblTenPhongBan).addComponent(lblHeSoCong)
														.addComponent(lblMoTa))
										.addGap(11)
										.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
												.addComponent(btnThem)
												.addComponent(txtheso, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE,
														328, Short.MAX_VALUE)
												.addComponent(txtten, GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
												.addComponent(txtid, GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
												.addComponent(txtmota, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE,
														328, Short.MAX_VALUE))))
						.addContainerGap()));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup().addContainerGap()
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblMaPhongBan)
								.addComponent(txtid))
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblTenPhongBan)
								.addComponent(txtten))
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblHeSoCong)
								.addComponent(txtheso))
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblMoTa)
								.addComponent(txtmota))
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(btnThem)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(scrollphongban, GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE).addGap(5)));
		contentPane.setLayout(gl_contentPane);
	}

	private String loadDataPhongBan() {
		return control.getListPhongban();
	}
}
